package net.halflite.mzkr.action.home;

import javax.annotation.Resource;

import net.halflite.mzkr.form.home.PasswordForm;
import net.halflite.mzkr.service.RegistedUserService;

import org.apache.struts.action.ActionMessages;
import org.seasar.struts.annotation.ActionForm;
import org.seasar.struts.annotation.Execute;
import org.seasar.struts.enums.SaveType;

/** パスワード変更のアクションクラス */
public class PasswordAction extends LoginedBaseAction {

	@Resource
	private RegistedUserService registedUserService;

	@ActionForm
	@Resource(name = "home_passwordForm")
	private PasswordForm form;

	/** 入力 */
    @Execute(validator = false)
    public String index() {
        return "index.jsp";
    }

    /** 登録 */
    @Execute(validate = "validate", saveErrors = SaveType.SESSION, input = "./?redirect=true")
    public String post() {
    	registedUserService.changePassword(findUserId(), form.password);
        return "success?redirect=true";
    }

    /** 完了 */
    @Execute(validator = false, removeActionForm = true)
    public String success() {
        return "success.jsp";
    }
    
    /** 現在のパスワード検証 */
    public ActionMessages validate() {
    	return registedUserService.validateRecentPassword(findUserId(), form.recent);
    }

}
